// pages/share/share_invite.js
const app = getApp();
import {
  UserModels
} from "../../utils/models/user/User-models";
var userModel = new UserModels;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navbarHeight: app.globalData.navbarHeight,
    isHeight: true,
    titleName: '蒲尽广佛',
    navBgColor: "yellow",
    isLeft: true,
    isMask: false,

    nickname: 'xcc',
    mobile: '13217588888',
    linkman: '张三',
    desc:'',
    invite_id: '',
    invite_code:'',
    detail: '<img src="/images/test/i4.png" style="width:100%" />',
    user:{},
    inviteUser:{}
  },

  // 更换邀请人
  changeInvite: function() {
    this.setData({
      isMask: true
    });
  },

  // 关闭遮罩
  closeMask: function() {
    this.setData({
      isMask: false,
      invite_id: ''
    });
  },

  // 获取昵称
  getNickname: function(e) {
    this.setData({
      nickname: e.detail.value
    });
  },

  // 获取手机号
  getMobile: function(e) {
    this.setData({
      mobile: e.detail.value
    });
  },

  // 获取真实姓名
  getLinkman: function(e) {
    this.setData({
      linkman: e.detail.value
    });
  },

  // 获取真实姓名
  getDescs: function(e) {
    this.setData({
      desc: e.detail.value
    });
  },

  // 获取邀请人id
  getInviteId: function(e) {
    this.setData({
      invite_code: e.detail.value
    });
  },
  changeInviteSure:function(){
    var that = this;
    userModel.changeInvite({invite_code:this.data.invite_code},function(res){
      console.log(res);
      if(res.code < 0){
        wx.showToast({
          title: '没有邀请人信息',
        })
      }else{
        that.setData({
          invite_user:res.data,
          isMask:false
        })
      }
    })
  },
  inviteInit: function (invite_id){
    var param = {
      invite_id:invite_id
    }
    var that = this;
    userModel.becomingPartner(param,function(res){
      if(res.code > 0){
        that.setData({
          user: res.data.user,
          invite_user: res.data.invite_user,
          invite_code: res.data.invite_user.invite_code,
          nickname:res.data.user.nickname,
          desc:res.data.user.desc,
          linkman:res.data.user.linkman,
          mobile:res.data.user.mobile,
        })
      }
    })
  },
  apply:function(){
    var invite_code = this.data.invite_code;
    console.log(invite_code);
    var param = {
      invite_code:this.data.invite_code,
      desc:this.data.desc,
      linkman:this.data.linkman,
      nickname:this.data.nickname,
      mobile:this.data.mobile,
    };
    userModel.submitPartner(param,function(res){
      if(res.code > 0){
        wx.showToast({
          title: '提交成功，等待审核',
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let invite_id = options.invite_id;
    this.inviteInit(invite_id);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})